import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { HttpService } from '../../service/http.service';
import { NzMessageService } from 'ng-zorro-antd/message';

@Component({
  selector: 'app-notice',
  templateUrl: './notice.component.html',
  styleUrls: ['./notice.component.css'],
})
export class NoticeComponent {
  public pageInfo: any = {
    pageSize: 10,
    pageNum: 1,
    total: 0,
  };
  public userDetails: any = {};
  public isAdministrator = false;
  public studyInfo: any = {
    id: 0,
    content: '',
    logDate: null,
    name: '',
    comment: '',
  };
  public dataList: any = [];

  constructor(
    private router: Router,
    private httpService: HttpService,
    private modalService: NzMessageService,
  ) {}
  ngOnInit() {
    const user = localStorage.getItem('user');
    if (user != null) {
      this.userDetails = JSON.parse(user);
      if ('administrators' == this.userDetails.userType) {
        this.isAdministrator = true;
      }
    } else {
      this.router.navigate(['/login']);
    }

    this.getList();
  }

  getList() {
    const url =
      '/rest/notice/pageNum/' +
      this.pageInfo.pageNum +
      '/pageSize/' +
      this.pageInfo.pageSize;
    let data = {};
    if (this.userDetails.id != 1) {
      data = {
        userId: this.userDetails.id,
      };
    }
    return this.httpService.post(url, data).subscribe((res: any) => {
      this.dataList = [];
      this.pageInfo.pageSize = res.page.pageSize;
      this.pageInfo.pageNum = res.page.pageNum;
      this.pageInfo.total = res.page.total;
      this.dataList = res.data;
    });
  }
}
